#include"date.h"
date::date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

bool date::operator<(const date& d)
{
	if (_year < d._year)
	{
		return true;
	}
	else if (_year < d._year && _month < d._month)
	{
		return true;
	}
	else if (_year < d._year && _month < d._month && _day < d._day)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool date::operator==(const date& d)
{
	return _year == d._year
		&& _month == d._month
		&& _day == d._day;
}

bool date::operator<=(const date& d)
{
	return *this < d || *this == d;
}

bool date::operator>(const date& d)
{
	return !(*this <= d);
}

bool date::operator>=(const date& d)
{
	return !(*this < d);
}

bool date::operator!=(const date& d)
{
	return !(*this == d);
}

int date::GetMonthDay(int year, int month)
{
	static int daysArr[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
	if(month == 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0))
	{
		return 28;
	}
	else
	{
		return daysArr[month];
	}
}

date& date::operator+=(int day)
{
	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		++_month;
		if (_month > 13)
		{
			++_year;
			_month = 1;
		}
	}
	return *this;
}

date date::operator+(int day)
{
	date tmp(*this);
	tmp += day;
	return tmp;
}

date& date::operator++()
{
	*this += 1;
	return *this;
}

date date::operator++(int)
{
	date d1= *this;
	*this += 1;
	return d1;
}



